<?php
$host = '127.0.0.1';
$user = 'root';
$pass = 'root';
$db = 'exam';
$port = '3306';
$prefix = 'ba_';
$mysqli = new mysqli($host, $user, $pass, $db, $port);
if ($mysqli->connect_errno) {
    echo 'CONNECT ERROR: ' . $mysqli->connect_error . PHP_EOL;
    exit(1);
}
$tables = ['exam_question', $prefix . 'exam_question'];
foreach ($tables as $table) {
    $res = $mysqli->query("SHOW TABLES LIKE '" . $table . "'");
    if ($res && $res->num_rows) {
        echo "Found table: $table\n";
        foreach (['single', 'multi', 'judge', 'blank', 'short'] as $t) {
            $r = $mysqli->query("SELECT COUNT(*) AS c FROM `" . $table . "` WHERE `type`='" . $t . "'");
            $row = $r->fetch_assoc();
            echo "$t: $row[c]\n";
        }
        echo "\n";
    }
}
$mysqli->close();
